package com.batchengine.service;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

/**
 * Created by sunil.incubator@yahoo.com.
 * User: sunil.kalva
 * Date: Jun 21, 2009
 * <p/>
 * This interface represents a service that is deployed and is run on a server. Each service has an associated port.
 * When the server accepts a connection on a port, it calls the <tt>service</tt> method of the <tt>Service</tt> that
 * is associated with the port.
 */
public interface Service {

    /**
     * This method is invoked exactly once when this service is placed into service.
     */
    public void init();

    /**
     * This method is invoked when this service needs to be intialized.
     *
     * @param reinit a reinit
     */
    public void init(boolean reinit);

    /**
     * Implement this method to handle a new connection.
     *
     * @param in  the input stream of the connection
     * @param out the output stream of the connection
     * @throws java.io.IOException if there is an I/O error
     */
    public void service(InputStream in, OutputStream out) throws IOException;

    /**
     * This method should return true if this service requires password-based authentication. When authentication
     * is required by the service, the server would prompt the user for a password.
     *
     * @return boolean
     */
    public boolean requiresAuthentication();

    /**
     * This method should set the name of the component/server
     *
     * @param serverName aSN
     */
    public void setServerName(String serverName);

    /**
     * This method should set the name of the component/server
     *
     * @return serverName
     */
    public String getServerName();

    public boolean handleCommand(String commandName, String[] args, PrintWriter writer);
}
